%include <Optional.h>

%typemap(imtype) boost::optional "IntPtr"

%typemap(ctype_no_pointer) boost::optional "Optional<$typemap(template_arg, $ltype)>";
%typemap(ctype) boost::optional "Optional<$typemap(template_arg, $ltype)>*";
%typemap(cstype) boost::optional "Optional$typemap(template_arg_capitalized, $ltype)";
%typemap(cstype) boost::optional* "Optional$typemap(template_arg_capitalized, $ltype)"; // This is to make csin more generic


%typemap(csout, excode=SWIGEXCODE) boost::optional 
{
	$typemap(cstype,$ltype) ret = new $typemap(cstype, $ltype)($imcall, true);$excode
    return ret;
}

%typemap (csin) boost::optional "$typemap(cstype, $ltype).getCPtr($csinput).Handle";

%typemap(in) boost::optional
%{
    $1 = &($input -> getUnderlyingValue());
%}

%typemap(out) boost::optional
%{
    $result = new $typemap(ctype_no_pointer, $ltype)($1);
%}

%apply boost::optional {boost::optional const &};
%apply boost::optional {$ltype const &};
